home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / PIL / ImageTk.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  203 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import Tkinter
  5. import Image
  6. _pilbitmap_ok = None
  7.  
  8. def _pilbitmap_check():
  9.     global _pilbitmap_ok
  10.     if _pilbitmap_ok is None:
  11.         
  12.         try:
  13.             im = Image.new('1', (1, 1))
  14.             Tkinter.BitmapImage(data = 'PIL:%d' % im.im.id)
  15.             _pilbitmap_ok = 1
  16.         except Tkinter.TclError:
  17.             _pilbitmap_ok = 0
  18.         except:
  19.             None<EXCEPTION MATCH>Tkinter.TclError
  20.         
  21.  
  22.     None<EXCEPTION MATCH>Tkinter.TclError
  23.     return _pilbitmap_ok
  24.  
  25.  
  26. class PhotoImage:
  27.     
  28.     def __init__(self, image = None, size = None, **kw):
  29.         if image is None:
  30.             if kw.has_key('file'):
  31.                 image = Image.open(kw['file'])
  32.                 del kw['file']
  33.             elif kw.has_key('data'):
  34.                 StringIO = StringIO
  35.                 import StringIO
  36.                 image = Image.open(StringIO(kw['data']))
  37.                 del kw['data']
  38.             
  39.         
  40.         if hasattr(image, 'mode') and hasattr(image, 'size'):
  41.             mode = image.mode
  42.             if mode == 'P':
  43.                 image.load()
  44.                 
  45.                 try:
  46.                     mode = image.palette.mode
  47.                 except AttributeError:
  48.                     mode = 'RGB'
  49.                 except:
  50.                     None<EXCEPTION MATCH>AttributeError
  51.                 
  52.  
  53.             None<EXCEPTION MATCH>AttributeError
  54.             size = image.size
  55.             (kw['width'], kw['height']) = size
  56.         else:
  57.             mode = image
  58.             image = None
  59.         if mode not in ('1', 'L', 'RGB', 'RGBA'):
  60.             mode = Image.getmodebase(mode)
  61.         
  62.         self._PhotoImage__mode = mode
  63.         self._PhotoImage__size = size
  64.         self._PhotoImage__photo = apply(Tkinter.PhotoImage, (), kw)
  65.         self.tk = self._PhotoImage__photo.tk
  66.         if image:
  67.             self.paste(image)
  68.         
  69.  
  70.     
  71.     def __del__(self):
  72.         name = self._PhotoImage__photo.name
  73.         self._PhotoImage__photo.name = None
  74.         
  75.         try:
  76.             self._PhotoImage__photo.tk.call('image', 'delete', name)
  77.         except:
  78.             pass
  79.  
  80.  
  81.     
  82.     def __str__(self):
  83.         return str(self._PhotoImage__photo)
  84.  
  85.     
  86.     def width(self):
  87.         return self._PhotoImage__size[0]
  88.  
  89.     
  90.     def height(self):
  91.         return self._PhotoImage__size[1]
  92.  
  93.     
  94.     def paste(self, im, box = None):
  95.         im.load()
  96.         image = im.im
  97.         if image.isblock() and im.mode == self._PhotoImage__mode:
  98.             block = image
  99.         else:
  100.             block = image.new_block(self._PhotoImage__mode, im.size)
  101.             image.convert2(block, image)
  102.         tk = self._PhotoImage__photo.tk
  103.         
  104.         try:
  105.             tk.call('PyImagingPhoto', self._PhotoImage__photo, block.id)
  106.         except Tkinter.TclError:
  107.             v = None
  108.             
  109.             try:
  110.                 import _imagingtk as _imagingtk
  111.                 
  112.                 try:
  113.                     _imagingtk.tkinit(tk.interpaddr(), 1)
  114.                 except AttributeError:
  115.                     _imagingtk.tkinit(id(tk), 0)
  116.  
  117.                 tk.call('PyImagingPhoto', self._PhotoImage__photo, block.id)
  118.             except (ImportError, AttributeError, Tkinter.TclError):
  119.                 raise 
  120.             except:
  121.                 None<EXCEPTION MATCH>(ImportError, AttributeError, Tkinter.TclError)
  122.             
  123.  
  124.             None<EXCEPTION MATCH>(ImportError, AttributeError, Tkinter.TclError)
  125.  
  126.  
  127.  
  128.  
  129. class BitmapImage:
  130.     
  131.     def __init__(self, image = None, **kw):
  132.         if image is None:
  133.             if kw.has_key('file'):
  134.                 image = Image.open(kw['file'])
  135.                 del kw['file']
  136.             elif kw.has_key('data'):
  137.                 StringIO = StringIO
  138.                 import StringIO
  139.                 image = Image.open(StringIO(kw['data']))
  140.                 del kw['data']
  141.             
  142.         
  143.         self._BitmapImage__mode = image.mode
  144.         self._BitmapImage__size = image.size
  145.         if _pilbitmap_check():
  146.             image.load()
  147.             kw['data'] = 'PIL:%d' % image.im.id
  148.             self._BitmapImage__im = image
  149.         else:
  150.             kw['data'] = image.tobitmap()
  151.         self._BitmapImage__photo = apply(Tkinter.BitmapImage, (), kw)
  152.  
  153.     
  154.     def __del__(self):
  155.         name = self._BitmapImage__photo.name
  156.         self._BitmapImage__photo.name = None
  157.         
  158.         try:
  159.             self._BitmapImage__photo.tk.call('image', 'delete', name)
  160.         except:
  161.             pass
  162.  
  163.  
  164.     
  165.     def width(self):
  166.         return self._BitmapImage__size[0]
  167.  
  168.     
  169.     def height(self):
  170.         return self._BitmapImage__size[1]
  171.  
  172.     
  173.     def __str__(self):
  174.         return str(self._BitmapImage__photo)
  175.  
  176.  
  177.  
  178. def getimage(photo):
  179.     photo.tk.call('PyImagingPhotoGet', photo)
  180.  
  181.  
  182. def _show(image, title):
  183.     
  184.     class UI(Tkinter.Label):
  185.         
  186.         def __init__(self, master, im):
  187.             if im.mode == '1':
  188.                 self.image = BitmapImage(im, foreground = 'white', master = master)
  189.             else:
  190.                 self.image = PhotoImage(im, master = master)
  191.             Tkinter.Label.__init__(self, master, image = self.image, bg = 'black', bd = 0)
  192.  
  193.  
  194.     if not Tkinter._default_root:
  195.         raise IOError, 'tkinter not initialized'
  196.     
  197.     top = Tkinter.Toplevel()
  198.     if title:
  199.         top.title(title)
  200.     
  201.     UI(top, image).pack()
  202.  
  203.